home *** CD-ROM | disk | FTP | other *** search
- #ifndef _AGF_H_
- #include <agf.h>
- #endif
-
- #define MAX_COFS 32
-
- void compress(FILE *in, FILE *out, int r, int mode)
- {
-
- quick a[MAX_COFS];
- quick x[MAX_COFS];
- quick y, e, z;
- float te, fe;
- int i, count;
- char ch, che;
- char flag ;
-
-
- count = 10000;
- for (i=0; i<MAX_COFS;i++) {
- a[i] = 0;
- x[i] = 0;
- }
- if (r!=1) {
- a[0] = 1;
- a[1] = 0;
- a[2] = 0;
- }
-
-
- if (r==1)
- printf("Gradient Descent Adaptation On\n");
-
-
- che = 0;
- ch = 0;
- z = 0;
- flag = 0;
- y = 0;
- while (!feof(in)) {
-
- /* Pass data to FIR inputs */
- for (i=(MAX_COFS-1); i>0; i--) {
- x[i] = x[i-1];
- }
- x[0] = z;
-
- /* Get FIR output */
- y = fir_out(x, a, MAX_COFS);
-
- ch = getc(in);
- if (!feof(in)) {
- if (mode==0) {
- z = c2Quick(ch);
- e = y - z;
- che = Quick2c(e);
- e = c2Quick(che);
- }else{
- /*z = y + e;
- e = c2Quick(ch);
- che = Quick2c(z);
- z = c2Quick(che);*/
- //y = fir_out(x, a, MAX_COFS);
- e = c2Quick(ch);
- z = y - e;
- che = Quick2c(z);
- z = c2Quick(che);
- }
-
-
- putc(che, out);
- if (r==1)
- gradient_descent(x, a, MAX_COFS, -e);
-
-
- /* Calculate total error */
- te =te + ((float) abs(che));
- count--;
- if (count<=0) {
- count = 10000;
- te = te/12800;
- printf("E: %f pc\n",te);
- te = 0;
- }
- }
- }
- for (i=0;i<MAX_COFS;i++) {
- #ifdef INTQUICK
- fe = (float) a[i];
- fe = fe/256;
- printf("%f\n",fe);
- #else
- printf("%f\n",a[i]);
- #endif
- }
-
- }
-
-
-
-
-
-
-
-